using UnityEngine;

public class ItemDropAfterDead : MonoBehaviour
{
	public float DropRate = 1f;

	public ItemData[] Item;

	public int[] DropNum;

	public Vector3 Offset = new Vector3(0f, 0.1f, 0f);

	private void Start()
	{
		if (DropNum.Length >= Item.Length)
		{
			return;
		}
		DropNum = new int[Item.Length];
		for (int i = 0; i < DropNum.Length; i++)
		{
			if (DropNum[i] <= 0)
			{
				DropNum[i] = 1;
			}
		}
	}

	public void DropItem()
	{
		if ((float)UnityEngine.Random.Range(0, 100) >= 99f * (1f - DropRate))
		{
			int num = UnityEngine.Random.Range(0, Item.Length);
			ItemData itemData = Item[num];
			Vector3 position = base.transform.position;
			Vector3 localScale = base.transform.localScale;
			int min = -(int)(localScale.x / 2f);
			Vector3 localScale2 = base.transform.localScale;
			float x = UnityEngine.Random.Range(min, (int)(localScale2.x / 2f));
			Vector3 localScale3 = base.transform.localScale;
			int min2 = (int)((0f - localScale3.z) / 2f);
			Vector3 localScale4 = base.transform.localScale;
			Vector3 position2 = DetectGround(position + new Vector3(x, 0f, UnityEngine.Random.Range(min2, (int)(localScale4.z / 2f))));
			UnitZ.gameNetwork.RequestSpawnItem(itemData.gameObject, itemData.NumTag, DropNum[num], position2, Quaternion.identity);
		}
	}

	private Vector3 DetectGround(Vector3 position)
	{
		if (Physics.Raycast(position, -Vector3.up, out RaycastHit hitInfo, 1000f))
		{
			return hitInfo.point + Offset;
		}
		return position;
	}
}
